//
//  TJEmployeeListCell.m
//  BaoDian
//
//  Created by mac on 2024/7/27.
//

#import "TJStaffListCell.h"
#import "TJUserPublishDataView.h"

@interface TJStaffListCell()

@property (nonatomic, weak) UIImageView *avatarImageView;
@property (nonatomic, weak) UILabel *nameLabel;
@property (nonatomic, weak) UILabel *stateLabel;
@property (nonatomic, weak) UILabel *dateLabel;
@property (nonatomic, weak) UILabel *acountLabel;
@property (nonatomic, weak) UILabel *douYinNameLabel;
@property (nonatomic, weak) UIButton *disableButton;
@property (nonatomic, weak) TJUserPublishDataView *dataView;

@end


@implementation TJStaffListCell


- (void)settingSubView {
    [super settingSubView];
    

    self.selectionStyle = UITableViewCellSelectionStyleNone;
    self.backgroundColor = UIColor.tj_backgroundColor;
    
    UIView *tj_contentView = [UIView addToView:self.contentView];
    tj_contentView.backgroundColor = UIColor.tj_1E1F23Color;
    tj_contentView.addCornerRadius(12);
    [tj_contentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.inset(16);
        make.top.offset(0);
    }];
    
    UIView *topView = [UIView addToView:tj_contentView];
    [topView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.inset(0);
        make.top.offset(0);
        make.height.offset(132);
    }];
    
    UIImageView *avatarImageView = [UIImageView addToView:topView];
    avatarImageView.addCornerRadius(40);
    [avatarImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.offset(16);
        make.width.height.offset(80);
    }];
 
    UILabel *nameLabel = [UILabel lableWithSuperView:topView font:UIFontBoldMake(18) color:UIColor.whiteColor title:@"罗征博" textAlignment:NSTextAlignmentCenter];
    [nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(avatarImageView.mas_right).offset(16);
        make.top.equalTo(avatarImageView);
    }];
    
    UILabel *stateLabel = [UILabel lableWithSuperView:topView font:UIFontMake(12) color:UIColorMake(0xFFAC3F) title:@"抖音未授权" textAlignment:NSTextAlignmentCenter];
    stateLabel.addCornerRadius(4);
    stateLabel.layer.borderWidth = 0.5;
    stateLabel.layer.borderColor = UIColorMake(0xFFAC3F).CGColor;
    [stateLabel sizeToFit];
    [stateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(nameLabel);
        make.right.inset(16);
        make.width.offset(stateLabel.tj_width + 4);
        make.height.offset(18);
    }];

    UIView *lineView = [UIView addToView:topView];
    lineView.backgroundColor = UIColorMake(0x2A2B31);
    [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.inset(16);
        make.height.offset(1);
        make.bottom.offset(0);
    }];
    
    UILabel *dateLabel = [UILabel lableWithSuperView:topView font:UIFontMake(14) color:UIColor.tj_8D9298Color title:nil textAlignment:NSTextAlignmentLeft];
    [dateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(nameLabel.mas_bottom).offset(10);
        make.left.equalTo(nameLabel);
    }];
    
    UILabel *acountLabel = [UILabel lableWithSuperView:topView font:UIFontMake(14) color:UIColor.tj_8D9298Color title:@"登录账号   ljp19980405435" textAlignment:NSTextAlignmentLeft];
    [acountLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(dateLabel.mas_bottom).offset(6);
        make.left.equalTo(dateLabel);
    }];
    
    UILabel *douYinNameLabel = [UILabel lableWithSuperView:topView font:UIFontMake(14) color:UIColor.tj_8D9298Color title:@"抖音信息   嘎嘎乱杀" textAlignment:NSTextAlignmentLeft];
    [douYinNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(acountLabel.mas_bottom).offset(6);
        make.left.equalTo(dateLabel);
    }];
    
    TJUserPublishDataView *dataView = [TJUserPublishDataView addToView:tj_contentView];
    dataView.backgroundColor = UIColorMake(0x2A2B31);
    dataView.addCornerRadius(8);
    [dataView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(lineView);
        make.height.offset(52);
        make.top.equalTo(topView.mas_bottom);
    }];
    
    UIView *bottomView = [UIView addToView:tj_contentView];
    [bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.inset(0);
        make.bottom.offset(0);
        make.top.equalTo(dataView.mas_bottom);
    }];
    
    UIButton *deleteButton = [UIButton buttonWithSuperView:bottomView font:UIFontMake(12) color:UIColor.tj_8D9298Color title:@"删除"];
    deleteButton.addCornerRadius(14);
    deleteButton.layer.borderWidth = 0.5;
    deleteButton.layer.borderColor = UIColor.tj_8D9298Color.CGColor;
    [deleteButton addTarget:self action:@selector(didClickDeleteButton) forControlEvents:UIControlEventTouchUpInside];
    [deleteButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.offset(0);
        make.left.inset(16);
        make.width.offset(48);
        make.height.offset(28);
    }];
    
    UIButton *disableButton = [UIButton buttonWithSuperView:bottomView font:UIFontMake(12) color:UIColor.tj_8D9298Color title:@"禁用"];
    disableButton.addCornerRadius(14);
    disableButton.layer.borderWidth = 0.5;
    disableButton.layer.borderColor = UIColor.tj_8D9298Color.CGColor;
    [disableButton addTarget:self action:@selector(didClickDisableButton) forControlEvents:UIControlEventTouchUpInside];
    [disableButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.offset(0);
        make.left.equalTo(deleteButton.mas_right).inset(12);
        make.width.offset(72);
        make.height.offset(28);
    }];
    
    UIButton *clockInButton = [UIButton buttonWithSuperView:bottomView font:UIFontMake(12) color:UIColor.whiteColor title:@"查看打卡"];
    clockInButton.addCornerRadius(14);
    [clockInButton addTarget:self action:@selector(didClickClockInButton) forControlEvents:UIControlEventTouchUpInside];
    clockInButton.backgroundColor = UIColorMake(0x2978F0);
    [clockInButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.offset(0);
        make.right.inset(16);
        make.width.offset(72);
        make.height.offset(28);
    }];
    
    _avatarImageView = avatarImageView;
    _nameLabel = nameLabel;
    _stateLabel = stateLabel;
    _dateLabel = dateLabel;
    _acountLabel = acountLabel;
    _douYinNameLabel = douYinNameLabel;
    _disableButton = disableButton;
    _dataView = dataView;
    
}

- (void)setModel:(TJStaffListModel *)model {
    _model = model;
    
    if ([model.openId isKindOfClass:NSString.class] && model.openId.length) {
        _stateLabel.text = @"抖音已授权";
        _stateLabel.textColor = UIColorMake(0x8D9298);
        _stateLabel.layer.borderColor = UIColorMake(0x8D9298).CGColor;
    } else {
        _stateLabel.text = @"抖音未授权";
        _stateLabel.textColor = UIColorMake(0xFFAC3F);
        _stateLabel.layer.borderColor = UIColorMake(0xFFAC3F).CGColor;
    }
    
    if (model.status.intValue == 0) {//启用
        [_disableButton setTitle:@"禁用" forState:UIControlStateNormal];
    } else {
        [_disableButton setTitle:@"启用" forState:UIControlStateNormal];
    }
    
    [_avatarImageView tj_setImageWithURL:model.pic.URL placeholderImage:[UIImage imageNamed:defaultAvatarName]];
    _nameLabel.text = model.realName;
    _dateLabel.text = [NSString stringWithFormat:@"创建时间   %@", model.createDate];
    _acountLabel.text = [NSString stringWithFormat:@"登录账号   %@", model.mobile];
    _douYinNameLabel.text = [NSString stringWithFormat:@"抖音信息   %@", model.nickname];
    
    _dataView.publishCountItem.textLabel.text = model.sendCount ?: @"0";
    _dataView.playerCountItem.textLabel.text = model.playCount;
    _dataView.likeCountItem.textLabel.text = model.diggCount;
    _dataView.commentCountItem.textLabel.text = model.commentCount;
//
}

- (void)didClickDeleteButton {
    if (_didClickDeleteButtonBlock) {
        _didClickDeleteButtonBlock();
    }
}

- (void)didClickDisableButton {
    if (_didClickDisableButtonBlock) {
        _didClickDisableButtonBlock();
    }
}

- (void)didClickClockInButton {
    if (_didClickClockInButtonBlock) {
        _didClickClockInButtonBlock();
    }
}


@end
